import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import 'swiper/css';

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import axios from 'axios'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/dist/index.css';
import $ from 'jquery'



import store from './store' // 导入 store

store.commit('setPermission', localStorage.getItem("permission")) 
store.commit('setRole', localStorage.getItem("role")) 

// 使用拦截器 
axios.interceptors.request.use(function (config) { 
    // 从localStorage中获取satoken 
    const satoken = localStorage.getItem("satoken"); 
    // 如果存在，就设置到headers中 
    if (satoken) { config.headers["satoken"] = satoken; } 
    // 返回修改后的config 
    return config;
});

// 使用默认配置 
// 从localStorage中获取satoken 
// const satoken = localStorage.getItem("satoken"); 
// // 如果存在，就设置到默认headers中 
// if (satoken) { axios.defaults.headers.common["satoken"] = satoken; }

const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.config.globalProperties.$axios = axios;
app.use(router).use(store).use(ElementPlus).use($); // 使用 store

app.config.globalProperties.$store = store; // 给 app 添加 store 属性
app.mount('#app')